fix: prevent premature context cancellation in writeRaw (WriteRawWithContext/PatchRawWithContext) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #32066
Conversation
…Context/PatchRawWithContext)
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
1 similar comment
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
Description
WriteRawWithContextandPatchRawWithContextreturn a*Responsewhose body is bound to an already-cancelled context. Reading the body then fails with a spuriouscontext canceled, even though the request succeeded server-side.Root Cause
Both methods route through
writeRaw, which wraps the context with a timeout viawithConfiguredTimeoutand thendefer cancelFunc()— the cancel fires before the caller can readresp.Body.The read path (
readRawWithDataWithContext) and delete path (DeleteRawWithContext) already fixed this (#18708) by routing throughClient.RawRequestWithContext, which wraps the context with a timeout but discards the cancel function — the comment explains: "when canceled, the request.Body will EOF when reading due to the way it streams data in."Fix
Route
writeRawthroughClient.RawRequestWithContextinstead of manually wrapping the context withwithConfiguredTimeout+defer cancelFunc(). This matches the pattern used byreadRawWithDataWithContext,DeleteRawWithContext, and all other raw methods.Testing
WriteRawWithContext/PatchRawWithContextnow return a body that remains readable after the function returnsRawRequestWithContext's internalwithConfiguredTimeoutcallcontext canceledFixes #31986